package com.lujieni.springbootflowable;

import org.flowable.engine.ProcessEngine;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.repository.Deployment;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;
import java.util.Map;

/**
 * 并行网关
 */
@SpringBootTest
class SpringbootFlowableApplicationTests6 {
    
    @Autowired
    private ProcessEngine processEngine;
    @Autowired
    private RuntimeService runtimeService;


    @Test
    void deploy() {
        RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deployment = repositoryService.createDeployment()
                .addClasspathResource("process/holiday3.bpmn20.xml")
                .name("并行网关")
                .deploy();
        System.out.println(deployment.getId());
    }

    /**
     * 并行网关
     * act_ru_execution表中会有3条数据:主数据和2条子数据
     * 每个用户任务就是一个execution表的一条数据,任务完成那条数据就没了,并行任务会同时存在多条数据,因为同一时间会存在多个用户任务
     * act_ru_task 会同时有2个任务
     */
    @Test
    void startProcess() {
        runtimeService.startProcessInstanceById("holiday3:1:4361ec83-8b2f-11f0-9fe4-5847ca7eb09c");
    }

    @Test
    public void completeTask(){
        TaskService taskService = processEngine.getTaskService();
        taskService.complete("0cf0e3e7-8b30-11f0-b527-5847ca7eb09c");
    }

}
